#include <iostream>
using namespace std;

int const maxn = 2001;
struct data { int l, r; };

data da[maxn];
int f1, f2, n, d;

int calc(int x)
{
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int t = min(d, da[i].r) - max(da[i].l, x) + 1;
		if (t > 0) ans += t;
	}
	return ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> f1 >> f2 >> d;
	f1 -= f2;
	for (int i = 0; i < n; i++) cin >> da[i].l >> da[i].r;

	int l = 1, r = d, mid = (l+r)/2;
	for (; l + 1 < r; mid = (l+r)/2) {
		if (calc(mid) < f1) r = mid - 1;
		else if (calc(mid) >= f1) l = mid;
	}
	if (calc(mid + 1) == f1) cout << mid+1 << "\n";
	else				     cout << mid   << "\n";
}
